<?php
class MemberVeriAction extends BaseAction {
	public function photo() {
		$Photo = M('Photo');
		$photo_condition['sort'] = '1';
		$photo_condition['state'] = '1';
		$photo_condition['verify'] = '0';
		$photolist = $Photo->where($photo_condition)->select();
		$count = count($photolist);
		
		// 导入分页类
   	 	import("ORG.Util.Page");
    	// 实例化分页类
    	$p = new Page($count, 18);
    	$p->setConfig('prev','<');  
		$p->setConfig('first','<<');
		$p->setConfig('last','>>');
		$p->setConfig('next','>');
		
		// 分页显示输出
    	$page = $p->show();
		$photolist = $Photo->order('photo_id DESC')->limit($p->firstRow.','.$p->listRows)->where($photo_condition)->select(); 
		
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$this->assign("photolist",$photolist);
		$this->assign('navi',"会员照片审核");
		$this->assign('title',"照片审核列表");
		$this->assign('page', $page);
		$this->display();
	}	
	
	public function photodelete() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Photo = M('Photo');
		$condition['photo_id'] = $_GET['photoid'];
		$data = $Photo->where($condition)->find();
		$result = $Photo->where($condition)->delete();
		if($result) {
			if(file_exists("Public/Uploads/photos/".$data['photo_url'])) {
				unlink("Public/Uploads/photos/".$data['photo_url']);
			}
			echo "<script language=\"javascript\">alert('删除成功！');window.location.href='../../main';</script>";
		}
		else 
			$this->error ( '数据写入错误！请重试...' );
	}
	
	public function photoallow() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Photo = M('Photo');
		$condition['photo_id'] = $_GET['photoid'];
		$data['proceed_time'] = "20".date('y-m-d H:i:s',time());
		$data['verify'] = '1';
		$result = $Photo->where($condition)->save($data);
		if($result)
			echo "<script language=\"javascript\">alert('通过成功！');window.location.href='../../main';</script>";
		else 
			$this->error ( '数据写入错误！请重试...' );
	}
	
	public function showuser() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Photo = M('Photo');
		$condition['photo_id'] = $_GET['photoid'];
		$result = $Photo->where($photo_condition)->find();
		if($result)
			$this->redirect('MemberInfo/info', array('id'=>$result['user_id']));
		else 
			$this->error ( '未找到该用户！请重试...' );
	}
	
	public function identity() {
		$Photo = M('Photo');
		$photo_condition['sort'] = '2';
		$photo_condition['state'] = '1';
		$photolist = $Photo->where($photo_condition)->select();
		$count = count($photolist);
		
		// 导入分页类
   	 	import("ORG.Util.Page");
    	// 实例化分页类
    	$p = new Page($count, 14);
    	$p->setConfig('prev',"<");  
		$p->setConfig('first','<<');
		$p->setConfig('last','>>');
		$p->setConfig('next','>');
		
		// 分页显示输出
    	$page = $p->show();
		$photolist = $Photo->order('photo_id DESC')->limit($p->firstRow.','.$p->listRows)->where($photo_condition)->select(); 
		
		for($i=0;$i<count($photolist);$i++) {
			if($photolist[$i]["verify"]==0) {
				$photolist[$i]["verify_cn"]="待审核";
			}
			else if($photolist[$i]["verify"]==1) $photolist[$i]["verify_cn"]="已通过";
			else $photolist[$i]["verify_cn"]="未通过";
			if($photolist[$i]["proceed_time"]=="") $photolist[$i]["proceed_time"]="-";
			$photolist[$i]["id"]=$count-$i;
		}
		
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$this->assign("photolist",$photolist);
		$this->assign('navi',"实名认证审核");
		$this->assign('title',"认证审核列表");
		$this->assign('page', $page);
		$this->display();
	}
	
	public function showidentity() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Photo = M('Photo');
		$Detail = M('Detail');
		$con_p['photo_id'] = $_GET['photoid'];
		$info_p = $Photo->where($con_p)->find();
		$con_d['user_id'] = $info_p['user_id'];
		$info_d = $Detail->where($con_d)->find();
		
		$this->assign("photo",$info_p);
		$this->assign("real_name",$info_d['real_name']);
		$this->assign("id_number",$info_d['id_number']);
		$this->assign('navi',"实名认证审核");
		$this->assign('title',"处理审核");
		$this->display('proceedidentity');
	}
	
	public function proceedidentity() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Photo = M('Photo');
		$condition['photo_id'] = $_GET['photoid'];
		$info = $Photo->where($condition)->find();
		if($info['verify']!=$_POST['identity']) $data['verify'] = $_POST['identity'];
		if($data) {
			$data['proceed_time'] = "20".date('y-m-d H:i:s',time()); 
			$result = $Photo->where($condition)->save($data);
			if($result)
				echo "<script language=\"javascript\">alert('处理成功！');window.location.href='../../identity';</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		}
		else echo "<script language=\"javascript\">alert('资料没有更新！');window.history.back();</script>";
	}
	
	public function message() {
		$Message = M('Message');
		$sort = $_GET['sort'];
		$msg_condition['sort'] = $sort;
		$msg_condition['available'] = '1';
		$msglist = $Message->where($msg_condition)->select();
		$count = count($msglist);
		
		// 导入分页类
   	 	import("ORG.Util.Page");
    	// 实例化分页类
    	$p = new Page($count, 14);
    	$p->setConfig('prev',"<");  
		$p->setConfig('first','<<');
		$p->setConfig('last','>>');
		$p->setConfig('next','>');
		
		// 分页显示输出
    	$page = $p->show();
		$msglist = $Message->order('msg_id DESC')->limit($p->firstRow.','.$p->listRows)->where($msg_condition)->select(); 
		
		for($i=0;$i<count($msglist);$i++) {
			if($msglist[$i]["verify"]==0) $msglist[$i]["verify_cn"]="待审核";
			else if($msglist[$i]["verify"]==1) $msglist[$i]["verify_cn"]="已通过";
			else $msglist[$i]["verify_cn"]="未通过";
			if($msglist[$i]["proceed_time"]=="") $msglist[$i]["proceed_time"]="-";
			$msglist[$i]["id"]=$count-$i;
		}
		
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$this->assign("msglist",$msglist);
		$this->assign('page', $page);
		if($sort==1) {
			$this->assign('navi',"状态审核");
			$this->assign('title',"状态审核列表");
			$this->display('status');
		}
		else if($sort==2) {
			$this->assign('navi',"站内信审核");
			$this->assign('title',"站内信审核列表");
			$this->display('letter');
		}
	}
	
	public function showletter() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Message = M('Message');
		$User = M('User');
		$condition['msg_id'] = $_GET['msgid'];
		$info = $Message->where($condition)->find();
		$con_u['user_id'] = $info['user_id'];
		$userinfo = $User->where($con_u)->find();
		$con_u['user_id'] = $info['target_id'];
		$targetinfo = $User->where($con_u)->find();
		
		$this->assign("letter",$info);
		$this->assign("user",$userinfo['user_name']);
		$this->assign("target",$targetinfo['user_name']);
		$this->assign('navi',"站内信审核");
		$this->assign('title',"处理审核");
		$this->display('proceedletter');
	}
	
	public function showstatus() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Message = M('Message');
		$User = M('User');
		$condition['msg_id'] = $_GET['msgid'];
		$info = $Message->where($condition)->find();
		$userinfo = $User->where($info['user_id'])->find();
		
		$this->assign("status",$info);
		$this->assign("user",$userinfo['user_name']);
		$this->assign('navi',"状态审核");
		$this->assign('title',"处理审核");
		$this->display('proceedstatus');
	}
	
	public function proceedletter() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Message = M('Message');
		$condition['msg_id'] = $_GET['msgid'];
		$info = $Message->where($condition)->find();
		if($info['verify']!=$_POST['letter']) $data['verify'] = $_POST['letter'];
		if($data) {
			if($info['title']!=$_POST['title']) $data['title'] = $_POST['title'];
			if($info['content']!=$_POST['content']) $data['content'] = $_POST['content'];
			$data['proceed_time'] = "20".date('y-m-d H:i:s',time()); 
			$result = $Message->where($condition)->save($data);
			if($result)
				echo "<script language=\"javascript\">alert('处理成功！');window.location.href='../../message/sort/2';</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		}
		else echo "<script language=\"javascript\">alert('资料没有更新！');window.history.back();</script>";
	}
	
	public function proceedstatus() {
		//防止页面乱码  
		header ( 'Content-type:text/html;charset=utf-8' );
		$Message = M('Message');
		$condition['msg_id'] = $_GET['msgid'];
		$info = $Message->where($condition)->find();
		if($info['verify']!=$_POST['status']) $data['verify'] = $_POST['status'];
		if($data) {
			if($info['content']!=$_POST['content']) $data['content'] = $_POST['content'];
			$data['proceed_time'] = "20".date('y-m-d H:i:s',time()); 
			$result = $Message->where($condition)->save($data);
			if($result)
				echo "<script language=\"javascript\">alert('处理成功！');window.location.href='../../message/sort/1';</script>";
			else 
				$this->error ( '数据写入错误！请重试...' );
		}
		else echo "<script language=\"javascript\">alert('资料没有更新！');window.history.back();</script>";
	}
}